package cn.edu.scau.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.scau.entity.Reply;
import cn.edu.scau.service.CommentService;



@Controller
@RequestMapping("/comment")
public class CommentController {

	@Autowired
	private CommentService commentService;

	public CommentService getCommentService() {
		return commentService;
	}

	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}

	/**
	 * 回复
	 * 
	 * @param reply
	 * 回复
	 * @param commentId
	 *  评论id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/reply")
	public String userReply(Reply reply, @RequestParam(name = "commentId") Integer commentId) {

		try {
			// 设置回复时间
			reply.setTime(new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").format(new Date().getTime()));
			// 进行保存
			this.getCommentService().reply(reply, commentId);
		} catch (Exception e) {
			e.printStackTrace();
			return "{" + '"' + "result" + '"' + ":" + '"' + false + '"' + "}";
		}

		return "{" + '"' + "result" + '"' + ":" + '"' + true + '"' + "}";

	}
}